﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using EnglishLibrary;

namespace DataAccess
{
    //create, read, delete, update Rate items
    public class RateDAO
    {
        private string _filePath;

        public string FilePath
        {
            get { return _filePath; }
            set { _filePath = value; }
        }

        public RateDAO(string profilePath)
        {
            _filePath = profilePath;
        }

        public RateDAO()
        {
            _filePath = string.Empty;
        }

        public List<Rate> GetListItems()
        {
            var list = new List<Rate>();
            var query = "SELECT RATEID, RATETEXT FROM RATE";

            try
            {
                DataProvider.OpenConnection(_filePath);
                var reader = DataProvider.ExecuteReader(query);

                while (reader.Read())
                {
                    var rateItem = new Rate();

                    if (!reader.IsDBNull(0))
                        rateItem.RateID = reader.GetString(0);
                    if (!reader.IsDBNull(1))
                        rateItem.RateText = reader.GetString(1);

                    list.Add(rateItem);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DataProvider.CloseConnection();
            }
            return list;
        }
    }
}
